<?php
include('include/config.inc.php');
if(!isset($_SESSION['s_activId'.$cfgPack])
  || (isset($_SESSION['s_userType'.$cfgPack]) && isset($cfgFileNames['dailyreportmaster'][$_SESSION['s_userType'.$cfgPack]]) 
      && $cfgFileNames['dailyreportmaster'][$_SESSION['s_userType'.$cfgPack]] == 0))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
  exit();
}
else
{
	$companyName  = "";
	$srNo         = 0;
	$delivaryDate = "";
	$address      = "";
	$userName     = ""; 
	$challanType  = "";
	$partySelect  = NULL;
	$party        = NULL;
  $msg = '<tr><td align="center" colspan="6"> <h2><font color="red"><b>Record Not Found...!</b></h2></font></td></tr>';
  $selectDeliveryChalan = "SELECT randrmaster.rAndRMasterId,party.companyName,randrmaster.srNo,supplier.companyName,randrmaster.address,randrmaster.complaintDate,randrmaster.targetDate
				  						       FROM randrmaster
				  						       JOIN party ON party.partyId = randrmaster.partyId
				  						       JOIN supplier ON supplier.supplierId = randrmaster.supplierId
											      WHERE rAndRMasterId = ".$_GET['rAndRMasterId']; 
  $selectQueryDeliveryChalan = mysql_query($selectDeliveryChalan);
	if($deliveryChalanRow = mysql_fetch_array($selectQueryDeliveryChalan))
  {
  	$rAndRMasterId = $deliveryChalanRow['rAndRMasterId'];
  	$companyName   = $deliveryChalanRow['companyName'];
  	$srNo          = $deliveryChalanRow['srNo'];
  	$companyName   = $deliveryChalanRow['companyName'];
  	$address       = $deliveryChalanRow['address'];
  	$complaintDate = $deliveryChalanRow['complaintDate'];
  	$targetDate    = $deliveryChalanRow['targetDate'];
  }
  $selectdeliverychallandetail = "SELECT randrdetail.rAndRDetailId,subCategory.subCategoryName,item.itemName,
                                         randrdetail.quantity,randrdetail.complaintDescription
                                    FROM randrdetail
                                    JOIN subcategory ON subcategory.subCategoryId = randrdetail.subCategoryId
                                    JOIN item ON item.itemId = randrdetail.itemId
                                   WHERE randrdetail.rAndRMasterId = ".$_REQUEST['rAndRMasterId']; 
  $deliverychallandetailQuery = mysql_query($selectdeliverychallandetail);
  $deliveryChalanArray = array();
  $deliveryChalanCount = 0;
  while($deliverychallandetailRow = mysql_fetch_array($deliverychallandetailQuery))
  {
  	
    $deliveryChalanArray[$deliveryChalanCount]['itemName'] = $deliverychallandetailRow['itemName'];
    $deliveryChalanArray[$deliveryChalanCount]['subCategoryName'] = $deliverychallandetailRow['subCategoryName'];
  	$deliveryChalanArray[$deliveryChalanCount]['quantity']        = $deliverychallandetailRow['quantity'];
  	$deliveryChalanArray[$deliveryChalanCount]['complaintDescription'] = $deliverychallandetailRow['complaintDescription'];
  	$deliveryChalanCount++;
  }
  if($deliveryChalanCount == 0)
  {
	  $msg = 'Record Not Found...!';
  }
  include("./bottom.php");
  $smarty->assign("msg",$msg);
  $smarty->assign("deliveryChalanArray",$deliveryChalanArray);
  $smarty->assign("companyName",$companyName);
  $smarty->assign("srNo",$srNo);
  $smarty->assign("companyName",$companyName);
  $smarty->assign("address",$address);
  $smarty->assign("complaintDate",$complaintDate);
  $smarty->assign("targetDate",$targetDate);
  $smarty->display("rAndRDetail.tpl");
}
?>